<template>
  <div class="nav-main">
    <SvgIcon class-name="logo" icon-class="logo" />
    <div ref="mainDiv" class="main">
      <div class="avatar">
        <img v-lazy="webInfo.getAvatar" alt="">
      </div>
      <div class="name">
        <img src="@/assets/name.svg" alt="">
      </div>
      <div class="icon-list">
        <a v-for="item in webInfo.getWebLinkInfo" :key="item.icon" :href="item.link" target="_blank">
          <SvgIcon class-name="icon" :icon-class="item.icon"/>
        </a>
      </div>
      <div class="search">
        <SvgIcon class-name="icon" icon-class="search"/>
        <input type="text" placeholder="搜索">
      </div>
    </div>
    <div class="next">
      <!--        <img src="@/assets/icons/next.svg" alt="" @click="toBlog">-->
      <SvgIcon class-name="icon" icon-class="next" />
    </div>
    <div ref="footerDiv" class="footer">
      <MyFooter font-color="#999" />
    </div>
  </div>
</template>

<script setup lang="ts">
import {onBeforeUnmount, onMounted, ref} from "vue";
import { useRouter } from 'vue-router'
import {webInfoStore} from "@/store";
import MyFooter from "@/components/MyFooter.vue";
import SvgIcon from "@/components/common/SvgIcon.vue";
const router = useRouter()
const webInfo = webInfoStore()
const mainDiv = ref<HTMLElement | null>(null)
const footerDiv = ref<HTMLElement | null>(null)
const handleClickOutside = (event: MouseEvent) => {
  if (!mainDiv.value || (mainDiv.value as HTMLElement).contains(event.target as Node)) {
    return
  }
  if (!footerDiv.value || (footerDiv.value as HTMLElement).contains(event.target as Node)) {
    return
  }
  router.push('/home')
}
onMounted(() => {
  document.addEventListener('click', handleClickOutside);
})
onBeforeUnmount(() => {
  document.removeEventListener('click', handleClickOutside);
})
</script>

<style scoped lang="less">
.nav-main {
  width: 100%;
  height: 100vh; // 使用100vh来确保高度占满视口
  background-size: cover;
  background-image: url("https://img.mikufufu.com/image/3.webp");
  position: relative;
  z-index: 1;
  &:hover{
    .next{
      transition: all 0.35s ease; /* 添加过渡效果 */
      filter: brightness(0.8);
      transform: translate(-50%, 15px) scale(1.1);
    }
  }
  &:after {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: -1;
  }
  .logo {
    position: absolute;
    top: 24px;
    left: 40px;
    width: 176px;
    height: 48px;
    color: #FFFFFF;
  }
  .main {
    position: absolute;
    padding: 20px;
    top: 50%;
    left: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transform: translate(-50%, -80%); // 垂直和水平居中
    color: #FFF;
    .avatar {
      border-radius: 50%;
      border: 1px solid #FFF;
      overflow: hidden;
    }
    .name {
      margin-top: 20px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .search {
      display: flex;
      align-items: center;
      margin-top: 20px;
      position: relative;
      .icon {
        position: absolute;
        top: 50%;
        left: 16px;
        width: 16px;
        height: 16px;
        margin-left: 16px;
        transform: translate(-50%, -50%);
        z-index: 1;
        &:hover {
          cursor: pointer;
        }
      }
      input {
        height: 32px;
        border: 1px solid #F1F1F1;
        border-radius: 8px;
        padding: 0 32px;
        margin-left: 16px;
        outline: none;
        color: #FFF;
        box-sizing: border-box;
        background-color: rgba(255, 255, 255, 0.12);
        backdrop-filter: blur(8.1px);
        &::placeholder {
          color: #FFF;
        }
        &:focus {
          border: 1px solid #EB5C88;
        }
        &:hover {
          border: 1px solid #EB5C88;
        }
      }
    }
    .icon-list {
      display: flex;
    }
  }
  .next {
    position: absolute;
    left: 50%;
    top: 80%;
    transform: translate(-50%, 0);
    color: #999999;
  }
  .footer {
    width: 100%;
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translate(-50%, 0);// 水平居中
  }
}
.icon {
  color: #FFF;
}
@media screen and (max-width: 768px) {
  .name {
    img {
      height: 50.4px;
      width: 160px;
    }
  }
  .avatar {
    height: 96px;
    width: 96px;
    img {
      height: 96px;
      width: 96px;
    }
  }
  .search {
    input {
      width: 320px;
    }
  }
  .icon-list{
    margin-top: 20px;
    .icon {
      margin-left: 10px;
    }
  }
  .icon {
    width: 25.6px;
    height: 25.6px;
  }
}
@media screen and (min-width: 768px) {
  .name {
    img {
      height: 63px;
      width: 200px;
    }
  }
  .avatar {
    height: 140px;
    width: 140px;
    img {
      height: 140px;
      width: 140px;
    }
  }
  .search {
    input {
      width: 400px;
    }
  }
  .icon-list{
    margin-top: 40px;
    .icon {
      margin-left: 20px;
    }
  }
  .icon {
    width: 32px;
    height: 32px;
  }
}
</style>
